package com.bjsxt.controller;

import com.bjsxt.pojo.Admin;
import com.bjsxt.pojo.Menu;
import com.bjsxt.pojo.PageA;
import com.bjsxt.pojo.TreeA;
import com.bjsxt.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/MenuController")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @RequestMapping("/findMenusLer")
    public List<TreeA> findMenusLer(@RequestParam(defaultValue = "0") Integer id, HttpSession session){
        Admin admin = (Admin) session.getAttribute("admin");
        return menuService.findMenus(admin.getAid(), id);
    }

    @RequestMapping("/findAllMenuLer")
    public PageA<Menu> findAllMenuLer(Integer page,Integer rows){
        return menuService.findAllMenu(page,rows);
    }

    @RequestMapping("/findAllMenuLer2")
    public List<TreeA> findAllMenuLer2(@RequestParam(defaultValue = "0") Integer id){
        return menuService.findAllMenu2(id);
    }

    @RequestMapping("/addMenuLer")
    public Integer addMenuLer(Menu menu){
        return menuService.addMenu(menu);
    }

    @RequestMapping("/changeMenuLer")
    public Integer changeMenuLer(Menu menu){
        return menuService.changeMenu(menu);
    }

    @RequestMapping("/removeMenuLer")
    public Integer removeMenuLer(Integer mid){
        return menuService.removeMenu(mid);
    }

    @RequestMapping("/findAllMenuLer3")
    public List<TreeA> findAllMenuLer3(){
        return menuService.findAllMenu3();
    }
}
